#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>


int main(int argc, char *argv[])
{
    struct gameState *state = newGame();
    int *bonus = malloc(sizeof(int));
    int i, j, handSize, deckSize, discardSize, tempCard, numActions;
    srand(time(NULL));
    //initialize state
    state->numPlayers = 2;
    state->whoseTurn = 0;

    for(i=0; i<100; i++){
        deckSize = (rand() % 100);
        handSize = (rand() % 100);
        discardSize = (rand() % 100);
        numActions = (rand() % 100);
        state->deckCount[0] = deckSize;
        state->handCount[0] = handSize+1;//has to have room for great_hall
        state->discardCount[0] = discardSize;
        state->numActions = numActions;
        state->hand[0][0] = great_hall;//Make sure that adventure can be played.
        //Fill deck, hand, and discard with random cards.
        for (j=0; j<deckSize; j++){
            state->deck[0][j] = (rand() % 27);
        }
        for (j=1; j<handSize; j++){
            state->hand[0][j] = (rand() % 27);
        }
        for (j=0; j<discardSize; j++){
            state->discard[0][j] = (rand() % 27);
        }

        if(state->deckCount == 0)
            printf("deck was empty at start of test");
        else
            tempCard = state->deck[0][state->deckCount[0]-1]; 

        /*printf("\nOriginal hand:\n");
        for (j=0; j<handSize; j++){
             printf("%d ", state->hand[0][j]);
        }
        cardEffect(great_hall,0,0,0,state,0,bonus);

        printf("\nModified hand:\n");
        for (j=0; j<state->handCount[0]; j++){
             printf("%d ", state->hand[0][j]);
        }
        printf("tempCard = %d\n", tempCard);*/
        if(state->deckCount == 0)
            printf("deck was empty at start of test");
        else
            tempCard = state->deck[0][state->deckCount[0]-1];

        cardEffect(great_hall,0,0,0,state,0,bonus);//run the card
        printf("handCount=%d handSize=%d\n", state->handCount[0], handSize);
        printf("hand[0][0]=%d tempCard=%d\n", state->hand[0][0], tempCard);
        printf("actions=%d\n", state->numActions);
        if( state->handCount[0] == handSize //Should be the same since we discard 1 card and drew 1 card
            && state->hand[0][0] == tempCard//Make sure that we took the top card off the deck and it replaced great_hall
            && state->numActions == numActions+1)//spent 1 action but gained 1.
        {
            printf("PASS\n");
        }
        else
            printf("FAIL\n");
    }
}
